require( "mysql" ) 
--variables
local Server = "[Server 1]"
local SqlOn = 1
local LOG_CURRENT = "gameweb_tools/log.txt"
local host = "127.0.0.1"
local username = ""
local password = ""
local db = ""
--end of variables
print("#################################")
print("##Gameweb Logging Script Loaded##")
print("#################################")
function WriteToLog( str )
	if SqlOn == 1 then
	local db, error = mysql.connect(host, username, password, db)    
	if (db == 0) then print(tostring(error) .. "\n") return end  
	local Log = Server .. ": " ..os.date() .. ": " .. str;
	test, isok, error = mysql.query(db, "INSERT INTO log (Log) VALUES('".. Log .."')");
	if (!isok) then
		print(tostring(error) .. "\n");
	end
	local succ, error = mysql.disconnect(db)
	if (not succ) then
	print( error );
	end
	else
	filex.Append( LOG_CURRENT, os.date() .. ": " .. str .. "\n" )
	end

end
WriteToLog("Server Started Up or Changed Map")

function ReadLog()
	return file.Read( LOG_CURRENT )
end

function ChangeLog( path )
	LOG_CURRENT = path
end

function playerDies( victim, weapon, killer )
	if killer:IsNPC() then
	WriteToLog( "A NPC has killed " .. victim:GetName() )
	elseif killer:IsPlayer() then
	WriteToLog( "Player " .. killer:GetName() .. " has killed " .. victim:GetName() )
	AddKill(killer)
	AddDeath(victim)
	else 
	WriteToLog( "Prop or World killed " .. victim:GetName() )
	end
end
 
hook.Add( "PlayerDeath", "playerDeathTest", playerDies )

function fPlayerDisconnect( ply )
	WriteToLog( ply:GetName() .. " steamID: " .. ply:SteamID() .. " has left the server." )
end
hook.Add( "PlayerDisconnected", "playerdisconnected", fPlayerDisconnect )

function FirstSpawn( ply )

	WriteToLog( ply:GetName() .. " has joined the server." )
	
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )

function ISaid( ply, text, team, death )
    
	WriteToLog( ply:Nick() .. ": " .. text )
	
end
hook.Add( "PlayerSay", "ISaid", ISaid );

hook.Add("WeaponEquip", "Weapon", function(weapon)
timer.Simple(0, function() 
		local ply = weapon:GetOwner()
		local array = {
				"weapon_crowbar",
				"weapon_pistol",
				"weapon_smg1",
				"weapon_frag",
				"weapon_physcannon",
				"weapon_crossbow",
				"weapon_shotgun",
				"weapon_357",
				"weapon_rpg",
				"weapon_ar2",
				"gmod_tool",
				"gmod_camera",
				"weapon_physgun"}
		if table.HasValue(array, weapon:GetClass())	then
		else
		WriteToLog( ply:GetName() .. " spawned a " .. weapon:GetClass() )
		end
 	end)
end)

function PropSpawn( ply, mdl )

WriteToLog( "Player " .. ply:GetName() .. " spawned a prop: " .. mdl )

end
hook.Add( "PlayerSpawnProp", "PropSpawn", PropSpawn )

function playerRespawn( ply )
 
	WriteToLog( "Player " .. ply:GetName() .. " spawned/respawned" )
 
end
 
hook.Add( "PlayerSpawn", "playerRespawn", playerRespawn )